package com.ruoyi.house_sale.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.house_sale.service.IHousemodelService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house_sale.domain.Housemodel;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 户型资料Controller
 * 
 * @author ruoyi
 * @date 2022-03-29
 */
@RestController
@RequestMapping("/house_sale/housemodel")
public class HousemodelController extends BaseController
{
    @Autowired
    private IHousemodelService housemodelService;

    /**
     * 查询户型资料列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:housemodel:list')")
    @GetMapping("/list")
    public TableDataInfo list(Housemodel housemodel)
    {
        startPage();
        List<Housemodel> list = housemodelService.selectHousemodelList(housemodel);
        return getDataTable(list);
    }

    /**
     * 导出户型资料列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:housemodel:export')")
    @Log(title = "户型资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Housemodel housemodel)
    {
        List<Housemodel> list = housemodelService.selectHousemodelList(housemodel);
        ExcelUtil<Housemodel> util = new ExcelUtil<Housemodel>(Housemodel.class);
        util.exportExcel(response, list, "户型资料数据");
    }

    /**
     * 获取户型资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('house_sale:housemodel:query')")
    @GetMapping(value = "/{modelid}")
    public AjaxResult getInfo(@PathVariable("modelid") Long modelid)
    {
        return AjaxResult.success(housemodelService.selectHousemodelByModelid(modelid));
    }

    /**
     * 新增户型资料
     */
    @PreAuthorize("@ss.hasPermi('house_sale:housemodel:add')")
    @Log(title = "户型资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Housemodel housemodel)
    {
        return toAjax(housemodelService.insertHousemodel(housemodel));
    }

    /**
     * 修改户型资料
     */
    @PreAuthorize("@ss.hasPermi('house_sale:housemodel:edit')")
    @Log(title = "户型资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Housemodel housemodel)
    {
        return toAjax(housemodelService.updateHousemodel(housemodel));
    }

    /**
     * 删除户型资料
     */
    @PreAuthorize("@ss.hasPermi('house_sale:housemodel:remove')")
    @Log(title = "户型资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{modelids}")
    public AjaxResult remove(@PathVariable Long[] modelids)
    {
        return toAjax(housemodelService.deleteHousemodelByModelids(modelids));
    }
}
